package com.xiehua.task.server.handler;

import com.xiehua.task.intf.AbsBusinessHandler;
import com.xiehua.task.job.TaskReverseDefualt;
import com.xiehua.task.job.bucket.DelayBucket;
import com.xiehua.task.job.bucket.FixedBucket;
import com.xiehua.task.job.pool.Job;
import com.xiehua.task.msg.TaskExecuteCompleteReqBody;
import com.xiehua.task.protocol.TaskPacket;
import com.xiehua.task.redis.RedisTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tio.core.ChannelContext;

import static com.xiehua.task.msg.BaseBody.RESULT_FAIL;
import static com.xiehua.task.msg.BaseBody.RESULT_SUCCESS;

public class TaskexEcuteCompleteReqHandler extends AbsBusinessHandler<TaskExecuteCompleteReqBody> {

    private static Logger log = LoggerFactory.getLogger(TaskexEcuteCompleteReqHandler.class);


    @Override
    public Class<TaskExecuteCompleteReqBody> bodyClass() {
        return TaskExecuteCompleteReqBody.class;
    }

    @Override
    public Object handler(TaskPacket packet, TaskExecuteCompleteReqBody bsBody, ChannelContext channelContext) throws Exception {
        log.info("收到客户端执行task的结果:{}", bsBody.toString());
        TaskReverseDefualt taskReverseDefualt = new TaskReverseDefualt(RedisTemplate.getJedis());
        if (RESULT_SUCCESS.equals(bsBody.getResult())) taskReverseDefualt.success(bsBody.getJobId());
        if (RESULT_FAIL.equals(bsBody.getResult())) taskReverseDefualt.fail(bsBody.getJobId());
        taskReverseDefualt.clear();
        return null;
    }
}
